﻿# Airlifted from CSR
# Overridden from vanilla.
release_from_prison_interaction = {
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_prison
	special_interaction = release_from_prison_interaction
	icon = prison

	desc = release_from_prison_interaction_desc

	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:demand_conversion = no
					scope:renounce_claims = no
					scope:banish = no
					scope:take_vows = no
					scope:recruit = no
					scope:disfigure = no
					scope:blind = no
					scope:castrate = no
				}
				desc = RELEASE_PRISONER_OFFER
			}
			desc = RELEASE_PRISONER_OFFER_CONDITIONAL
		}
	}

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			#AGOT Added
			NOT = { has_character_flag = keep_imprisoned }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}

	on_accept = {
		if = {
			limit = { scope:recipient = { has_character_modifier = allowed_to_go_outside } }
			scope:recipient = { remove_character_modifier = allowed_to_go_outside }
		}
		if = {
			limit = { scope:recipient = { has_character_modifier = moldy_gruel_diet } }
			scope:recipient = { remove_character_modifier = moldy_gruel_diet }
		}
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }

			scope:recipient = {
				# Demand Conversion
				if = {
					limit = { scope:demand_conversion = yes }
					demand_conversion_interaction_effect = yes
					add_opinion = {
						modifier = demanded_my_conversion_opinion
						target = scope:actor
					}

					# Struggle Catalyst
					if = {
						limit = {
							scope:actor = {
								any_character_struggle = {
									involvement = involved
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_demanding_important_conversion
										CHAR = scope:recipient
									}
								}
							}
						}
						scope:actor = {
							every_character_struggle = {
								involvement = involved
								limit = {
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_demanding_important_conversion
										CHAR = scope:recipient
									}
								}
								activate_struggle_catalyst = {
									catalyst = catalyst_demanding_important_conversion
									character = scope:actor
								}
							}
						}
					}
				}

				# Banish Landed Character
				if = {
					limit = {
						scope:banish = yes
						scope:recipient = { is_landed_or_landless_administrative = yes }
					}
					#AGOT Modified, add NW banishment
					# banish_effect = { BANISHER = scope:actor }
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}
						add_character_flag = {flag = agot_betrothal_unwillingly_broken days = 1 }
						if = {
							limit = {
								agot_can_be_expelled_maester_trigger = yes
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}
					else = {
						agot_banish_effect = { BANISHER = scope:actor }
					}
					if = {
						limit = {
							NOT = {
								scope:actor = {
									has_banish_reason = scope:recipient
								}
							}
						}
						scope:actor = { add_tyranny = banishment_tyranny_gain }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# Banish Unlanded Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_landless_adventurer = no
								is_pool_character = no # It is possible for them to end up in the pool between the interaction being sent, and it being accepted
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
							NOR = {
								has_character_flag = realm_priest
								has_character_flag = was_bookmaker
							}
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							has_any_artifact = yes
						}
						every_character_artifact = {
							#AGOT Modified
							limit = { NOT = { has_variable = maesterwork } }
							set_owner = {
								target = scope:actor
								history = {
									location = scope:recipient.location
									actor = scope:recipient
									recipient = scope:actor
									type = stolen
								}
							}
							scope:actor = {
								if = {
									limit = {
										NOT = { has_variable = stolen_artifact }
									}
									set_variable = {
										name = stolen_artifact
										value = 1
									}
								}
								else = {
									change_variable = {
										name = stolen_artifact
										add = 1
									}
								}
							}
						}
					}
					#AGOT Modified, add NW banishment
					# banish = yes
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}
						if = {
							limit = {
								agot_can_be_expelled_maester_trigger = yes
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}
					else = {
						agot_banish_effect = { BANISHER = scope:actor }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# 'Banish' Pool Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_playable_character = no
								is_pool_character = yes # They'll just leave for the pool
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}

					#AGOT Added, add NW banishment
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}
						if = {
							limit = {
								agot_can_be_expelled_maester_trigger = yes
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}

					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}

				#AGOT Added, Banish to Essos - Landed Character
				if = {
					limit = {
						scope:agot_banish_to_essos = yes
						scope:recipient = {
							is_landed = yes
						}
					}
					if = {
						limit = {
							agot_can_be_expelled_maester_trigger = yes
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					if = {
						limit = {
							NOT = {
								scope:actor = {
									has_banish_reason = scope:recipient
								}
							}
						}
						scope:actor = { add_tyranny = banishment_tyranny_gain }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				#AGOT Added, Banish to Essos - Unlanded Character
				else_if = {
					limit = {
						AND = {
							scope:agot_banish_to_essos = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = no # It is possible for them to end up in the pool between the interaction being sent, and it being accepted
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
							NOT = {
								has_character_flag = realm_priest
							}
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							has_any_artifact = yes
						}
						every_character_artifact = {
							limit = { NOT = { has_variable = maesterwork } }
							set_owner = {
								target = scope:actor
								history = {
									location = scope:recipient.location
									actor = scope:recipient
									recipient = scope:actor
									type = stolen
								}
							}
							scope:actor = {
								if = {
									limit = {
										NOT = { has_variable = stolen_artifact }
									}
									set_variable = {
										name = stolen_artifact
										value = 1
									}
								}
								else = {
									change_variable = {
										name = stolen_artifact
										add = 1
									}
								}
							}
						}
					}
					if = {
						limit = {
							agot_can_be_expelled_maester_trigger = yes
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				#AGOT Added, Banish to Essos - Pool Character
				else_if = {
					limit = {
						AND = {
							scope:agot_banish_to_essos = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = yes # They'll just leave for the pool
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							agot_can_be_expelled_maester_trigger = yes
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}

				# Recruit Character
				if = {
					limit = { scope:recruit = yes }
					if = {
						limit = {
							scope:actor = {
								culture = {
									has_cultural_parameter = can_recruit_prisoners_easily
								}
							}
						}
						add_opinion = {
							modifier = loyal_servant
							target = scope:actor
						}
						scope:actor = {
							if = {
								limit = {
									can_add_hook = {
										target = scope:recipient
										type = loyalty_hook
									}
								}
								add_hook = {
									type = loyalty_hook
									target = scope:recipient
								}
							}
						}
					}
					else = {
						add_opinion = {
							modifier = demanded_recruitment
							target = scope:actor
						}
					}
					scope:actor = {
						if = {
							limit = {
								AND = {
									scope:actor.faith = {
										has_doctrine = tenet_communal_possessions
									}
									scope:recipient = {
										has_trait = peasant_leader
									}
								}
							}
							scope:actor = {
								add_piety = medium_piety_gain
							}
						}
					}
					scope:actor = {
						add_courtier = scope:recipient
					}
				}

				# Renounce Claims
				if = {
					limit = { scope:renounce_claims = yes }
					add_opinion = {
						modifier = demanded_claim_renouncement
						target = scope:actor
					}
					scope:recipient = {
						every_claim = {
							explicit = yes
							limit = {
								save_temporary_scope_as = temp_claim
								OR = {
									holder = scope:actor
									AND = {
										exists = holder
										NOT = { prev = { target_is_liege_or_above = scope:actor } }
										holder = { target_is_liege_or_above = scope:actor }
									}
									scope:actor = {
										any_held_title = {
											is_de_jure_liege_or_above_target = scope:temp_claim
										}
									}
								}
							}
							scope:recipient = { remove_claim = prev }
						}
					}
				}

				# Gain Hook
				if = {
					limit = { scope:gain_hook = yes }
					add_opinion = {
						modifier = demanded_hook
						target = scope:actor
					}
					scope:actor = {
						add_hook = { #Hook effect must match gain_hook option condition
							target = scope:recipient
							type = favor_hook
						}
					}
				}

				# Take Vows
				if = {
					limit = { scope:take_vows = yes }
					send_child_to_clergy_effect = yes
					#Does Byzan go hay-wire with deposing vassals?
					#AGOT Disabled
					#if = {
					#	limit = {
					#		scope:actor = {
					#			is_ai = yes
					#			culture = { has_cultural_pillar = heritage_byzantine }
					#		}
					#	}
					#	debug_log = debug_ai_byzan_forced_vows_on_prison_release
					#	debug_log_scopes = yes
					#}
					#Does the AI in general go haywire with deposing prisoners?
					#AGOT Modified
					#else_if = {
					if = {
						limit = {
							scope:actor = { is_ai = yes }
						}
						debug_log = debug_ai_forced_vows_on_prison_release
						debug_log_scopes = yes
					}
				}

				# Take Vows
				if = {
					limit = { scope:become_executioner = yes }
					release_as_executioner_effect = yes
				}

				if = { #!#!
					limit = { scope:become_court_whore = yes }
					scope:recipient = {
						add_character_modifier = {
							modifier = court_whore_prison_modifier
						}
					}
					scope:actor = {
						court_position_grant_effect = {
							EMPLOYER = scope:actor
							POS = court_whore
							CANDIDATE = scope:recipient
						}
						save_scope_as = liege
					}
				}

				# Disfigure
				if = {
					limit = { scope:disfigure = yes }

					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

					show_as_tooltip = {
						scope:recipient = {
							add_trait = disfigured
						}
					}

					torture_blind_castrate_disfigure_opinion_effect = { VERB = disfigured }

					scope:actor = {
						trigger_event = {
							id = prison.1030
							days = 1
						}
					}
				}

				# Blind
				if = {
					limit = { scope:blind = yes }
					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

					show_as_tooltip = {
						scope:recipient = {
							add_trait = blind
						}
					}

					# Merciful Blindings
					scope:actor = {
						if = {
							limit = {
								culture = { has_cultural_parameter = merciful_blinding }
								OR = {
									has_execute_reason = scope:recipient
									has_banish_reason = scope:recipient
								}
							}
							add_piety = medium_piety_gain
						}
					}

					torture_blind_castrate_disfigure_opinion_effect = { VERB = blinded }

					scope:actor = {
						trigger_event = {
							id = prison.1020
							days = 1
						}
					}

					# If we're a clan this interaction affects unity
					if = {
						limit = { scope:actor.culture = { has_cultural_parameter = merciful_blinding } } # If actor's culture has Merciful Blindings, they lose less unity
						add_clan_unity_interaction_effect = {
							CHARACTER = scope:actor
							TARGET = scope:recipient
							VALUE = minor_unity_loss
							DESC = clan_unity_blinding.desc
							REVERSE_NON_HOUSE_TARGET = no
						}
					}
					else = {
						add_clan_unity_interaction_effect = {
							CHARACTER = scope:actor
							TARGET = scope:recipient
							VALUE = medium_unity_loss
							DESC = clan_unity_blinding.desc
							REVERSE_NON_HOUSE_TARGET = no
						}
					}
				}

				# Castrate
				if = {
					limit = { scope:castrate = yes }
					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

					show_as_tooltip = {
						scope:recipient = {
							if = {
								limit = {
									age < 10
								}
								ep3_child_castration_effect = yes
							}
							else = {
								ep3_youth_castration_effect = yes
							}
						}
					}

					torture_blind_castrate_disfigure_opinion_effect = { VERB = castrated }

					scope:actor = {
						trigger_event = {
							id = prison.1025
							days = 1
						}
					}

					# If we're a clan this interaction affects unity
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = major_unity_loss
						DESC = clan_unity_abelarding.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
				}

				#AGOT Added, MW switch sides
				if = {
					limit = {
						scope:mega_war_switch_sides = yes
					}

					agot_mw_fetch_story_scopes_from_chars_effect = { CHARACTER_1 = actor CHARACTER_2 = recipient }

					scope:actor = {
						if = { # switch to rebels?
							limit = {
								scope:mw_crown_story ?= { is_target_in_variable_list = { name = mw_loyalist_list target = scope:recipient } }
							}
							agot_mw_join_rebels_effect = { RULER = scope:recipient REBEL_LEADER = scope:mw_rebel_story.story_owner }
						}
						else = {
							agot_mw_join_loyalists_effect = { RULER = scope:recipient CROWN = scope:mw_crown_story.story_owner }
						}
					}
				}
				#AGOT Added, Strip Knighthood
				if = {
					limit = {
						scope:agot_strip_knighthood = yes
					}
					agot_strip_knighthood_as_punishment_effect = { STRIPPER = scope:actor KNIGHT = scope:recipient }
				}

				# No Demands Added
				if = {
					limit = {
						scope:demand_conversion = no
						scope:renounce_claims = no
						scope:banish = no
						scope:gain_hook = no
						scope:take_vows = no
						scope:become_executioner = no
						scope:become_court_whore = no
						scope:recruit = no
						scope:disfigure = no
						scope:blind = no
						scope:castrate = no
						#AGOT Added
						scope:mega_war_switch_sides = no
						scope:agot_strip_knighthood = no
						scope:agot_banish_to_essos = no
					}
					# Notification to the imprisoner
					scope:actor = {
						send_interface_toast = {
							type = event_toast_effect_neutral
							title = recipient_released_from_prison
							left_icon = scope:recipient
							scope:recipient = {
								# CSR: Disable opinion impact for slaves
								if = {
									limit = {
										NOT = { has_relation_slave_owner = scope:actor }
									}
									add_opinion = {
										modifier = released_from_prison
										target = scope:actor
									}
								}
							}
						}
						scope:actor = {
							# CSR: Disable dread and stress impact for slaves
							if = {
								limit = {
									NOT = { has_relation_slave = scope:recipient }
								}
								add_dread = minor_dread_loss
								stress_impact = {
									sadistic = medium_stress_impact_gain
									callous = minor_stress_impact_gain
								}
							}
						}
						# Struggle impact
						if = {
							limit = {
								any_character_struggle = {
									involvement = involved
									#AGOT Modified
									#is_struggle_type = iberian_struggle
									is_struggle_type = btw_struggle
									OR = {
										has_struggle_phase_parameter = release_prisoner_diff_culture_gives_prestige
										#AGOT Disabled
										#has_struggle_phase_parameter = release_prisoner_diff_faith_gives_prestige
									}
								}
								#AGOT Modified, no faith in struggle
								#is_diff_faith_or_culture_trigger = {
								is_diff_culture_trigger = {
									CHAR = scope:recipient
									STATUS = involved
								}
							}
							add_prestige = medium_prestige_gain
						}

						# Struggle Catalyst
						if = {
							limit = {
								any_character_struggle = {
									involvement = involved
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_release_important
										CHAR = scope:recipient
									}
								}
							}
							every_character_struggle = {
								involvement = involved
								limit = {
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_release_important
										CHAR = scope:recipient
									}
								}
								activate_struggle_catalyst = {
									catalyst = catalyst_release_important
									character = scope:actor
								}
							}
						}
						#AGOT Disabled
						# if = {
						# 	limit = {
						# 		fp3_struggle_involves_one_supporter_and_one_detractor = {
						# 			FIRST = scope:actor
						# 			SECOND = scope:recipient
						# 		}
						# 		any_character_struggle = {
						# 			involvement = involved
						# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						# 				CATALYST = catalyst_release_supporter_detractor
						# 				CHAR = scope:recipient
						# 			}
						# 		}
						# 	}
						# 	every_character_struggle = {
						# 		involvement = involved
						# 		limit = {
						# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						# 				CATALYST = catalyst_release_supporter_detractor
						# 				CHAR = scope:recipient
						# 			}
						# 		}
						# 		activate_struggle_catalyst = {
						# 			catalyst = catalyst_release_supporter_detractor
						# 			character = scope:actor
						# 		}
						# 		log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_release_supporter_detractor }
						# 	}
						# }
					}

					# If we're a clan (and not making any demands) this interaction affects unity
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = minor_unity_gain
						DESC = clan_unity_released_from_own_prison.desc
						REVERSE_NON_HOUSE_TARGET = no
					}

					# LEGITIMACY GAIN FROM RELEASING DUKES AND ABOVE
					if = {
						limit = {
							exists = scope:recipient.primary_title
							scope:recipient.primary_title.tier >= tier_duchy
						}
						# Minus 2, since we want Duchy to be 1, and it's normally 3
						save_scope_value_as = {
							name = title_tier_minus_2
							value = {
								value = scope:recipient.primary_title.tier
								subtract = 2
							}
						}
						scope:actor = {
							send_interface_toast = {
								type = msg_legitimacy_gain
								title = legitimacy_gain_toast
								left_icon = scope:actor
								right_icon = scope:recipient
								add_legitimacy = {
									value = {
										value = miniscule_legitimacy_gain
										multiply = scope:title_tier_minus_2
									}
								}
							}
						}
					}
				}
				else = {
					scope:actor = {
						trigger_event = char_interaction.0160
					}
				}

				# If a child was imprisoned due to yearly_4021 they'll come back to say hi
				if = {
					limit = {
						exists = var:marked_for_revenge_in_event_yearly_4021
					}
					add_opinion = {
						modifier = abandoned_me_opinion
						target = var:marked_for_revenge_in_event_yearly_4021
					}
					if = {
						limit = {
							var:marked_for_revenge_in_event_yearly_4021 = {
								is_alive = yes
								is_ai = no
							}
						}
						save_scope_as = child
						if = {
							limit = { #Make sure they're sadistic!
								NOT = { has_trait = sadistic }
								number_of_personality_traits < personality_trait_limit
							}
							add_trait = sadistic
						}
						var:marked_for_revenge_in_event_yearly_4021 = {
							add_character_flag = { #TO make sure that they don't get spammed about the release
								flag = block_for_prison_release_notification
								days = 10
							}
							trigger_event = yearly.4022
						}
						remove_variable = marked_for_revenge_in_event_yearly_4021
					}
				}

				if = {
					limit = {
						is_imprisoned = yes
						# Release is handled in follow-up events
						scope:disfigure = no
						scope:blind = no
						scope:castrate = no
					}
					release_from_prison = yes
				}
			}

			# FP3 - If prisoner is important for war
			scope:actor = { # FP3
				if = {
					limit = {
						exists = scope:recipient.house
						any_character_war = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
					}
					random_character_war = {
						limit = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
						primary_attacker = {
							hidden_effect = {
								send_interface_message = {
									type = event_war_good
									title = lesson_war_final_notes_victory_step_1
									left_icon = scope:recipient
									right_icon = scope:actor

									show_as_tooltip = {
										scope:recipient = { release_from_prison = yes }
										add_prestige = major_prestige_gain
										prev.primary_defender = { add_prestige = major_prestige_loss }
									}
								}
							}
							add_prestige = major_prestige_gain
							prev.primary_defender = { add_prestige = major_prestige_loss }
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0161
		}
	}

	send_option = {
		flag = demand_conversion
		localization = "RELEASE_DEMAND_CONVERSION"
		is_shown = {
			NOT = { scope:recipient.faith = scope:actor.faith }
			#Added, NW doesn't care about faith
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_close_or_extended_family_of = scope:actor
						is_vassal_of = scope:actor
					}
				}
			}

			# Cannot ask Landed Rulers to convert if they're not your vassal
			custom_description = {
				text = cannot_demand_unsubordinate_landed_ruler_conversion
				scope:recipient = {
					trigger_if = {
						limit = {
							is_playable_character = yes
						}
						is_vassal_or_below_of = scope:actor
					}
				}
			}

			# Cannot ask Religious Heads to convert
			custom_description = {
				text = cannot_demand_religious_head_conversion
				NOT = {
					AND = {
						exists = scope:recipient.faith.religious_head
						scope:recipient.faith.religious_head = scope:recipient
					}
				}
			}
			# Cannot ask Holy Order Master to convert
			custom_description = {
				text = cannot_demand_holy_order_master_conversion
				NAND = {
					exists = scope:recipient.faith
					scope:recipient.faith = {
						any_faith_holy_order = { leader = scope:recipient }
					}
				}
			}
			#AGOT Added, doctrine_syncretism_the_cult
			custom_description = {
				text = AGOT_FAITH_CANNOT_DEMAND_CONVERSION
				NOT = {
					scope:actor.faith = {
						has_doctrine_parameter = cannot_demand_conversion
					}
				}
			}			
		}
	}

	send_option = {
		flag = renounce_claims
		localization = RELEASE_RENOUNCE_CLAIMS
		is_shown = {
			custom_description = {
				text = "release_renounce_claims"
				subject = scope:recipient
				scope:recipient = {
					any_claim = {
						explicit = yes
						save_temporary_scope_as = temp_claim
						OR = {
							holder = scope:actor
							AND = {
								NOT = { prev = { target_is_liege_or_above = scope:actor } }
								trigger_if = {
									limit = {
										exists = holder
									}
									holder = { target_is_liege_or_above = scope:actor }
								}
							}
							scope:actor = {
								any_held_title = {
									is_de_jure_liege_or_above_target = scope:temp_claim
								}
							}
						}
					}
				}
			}
		}
		current_description = {
			desc = RELEASE_RENOUNCE_CLAIMS_DESC
		}
	}

	send_option = {
		flag = banish
		localization = "RELEASE_BANISH"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						AND = {
							is_playable_character = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_playable_character = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_playable_character = no
							is_ruler = no
							gold > 100
							scope:actor.ai_greed >= high_positive_ai_value
						}
						AND = {
							scope:actor = {
								has_banish_reason = scope:recipient
							}
							scope:actor = {
								opinion = {
									target = scope:recipient
									value <= medium_negative_opinion
								}
							}
						}
					}
				}
			}
			#AGOT Modified, can attempt to banish anyone
			# if they can be sent to NW, or are in the actor's realm or in the pool
			# trigger_if = {
			# 	limit = {
			# 		scope:recipient = {
			# 			is_playable_character = yes
			# 		}
			# 	}
			# 	scope:recipient = {
			# 		is_vassal_of = scope:actor
			# 	}
			# }
			# trigger_else = {
			# 	scope:recipient = {
			# 		is_courtier_of = scope:actor
			# 	}
			# }
			OR = {
				agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
				scope:recipient = {
					OR = {
						target_is_liege_or_above = scope:actor
						is_pool_character = yes
					}
				}
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:take_vows = no
			}
			scope:recruit = no #Should be impossible to have both but just in case
			NOT = {
				scope:recipient = {
					is_spouse_of = scope:actor
				}
			}
			# CSR: Disable Banish for slaves since they will be returned automatically
			scope:recipient = {
				carnx_is_slave_trigger = no
			}

			#AGOT Added, NW cannot banish
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
			scope:recipient = {
				NOR = {
					has_trait = nightswatch
					has_trait = high_septon
				}
			}
			scope:agot_banish_to_essos = no
		}
	}

	send_option = {
		flag = gain_hook
		localization = "RELEASE_GAIN_HOOK"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_vassal_of = scope:actor
						AND = {
							exists = liege
							liege = scope:actor
						}
					}
				}
			}
		}
		is_valid = {
			scope:actor = {
				can_add_hook = {
					type = favor_hook #Matches the hook added in the on_accept
					target = scope:recipient
				}
			}
			# CSR: Adopted from Unofficial Patch
			NOT = {
				scope:actor = {
					has_hook_of_type = {
						type = favor_hook
						target = scope:recipient
					}
				}
			}
		}
	}

	send_option = {
		flag = take_vows
		localization = "RELEASE_TAKE_VOWS"
		is_shown = {
			scope:actor.faith = {
				has_doctrine_parameter = take_vows_active
			}
			# CSR: Disable Take Vows for slaves since they will be returned automatically
			scope:recipient = {
				carnx_is_slave_trigger = no
			}
			#AGOT Added
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			#Handle AI
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				#We're AI and Byzantium
				#AGOT Disabled
				#trigger_if = {
				#	limit = {
				#		scope:actor = {
				#			culture = { has_cultural_pillar = heritage_byzantine }
				#		}
				#	}
				#	scope:recipient = {
				#		is_ai = yes #Not gonna depose player characters, for now
				#		OR = {
				#			is_close_or_extended_family_of = scope:actor
				#			is_vassal_or_below_of = scope:actor #Weigh this for Byz AI in the modifiers below
				#			has_relation_rival = scope:actor
				#			is_courtier_of = scope:actor
				#		}
				#		NOT = {
				#			is_heir_of = scope:actor
				#		}
				#	}
				#	#Get rid of rivals despite potentially liking them
				#	trigger_if = {
				#		limit = {
				#			scope:recipient = { has_relation_rival = scope:actor }
				#		}
				#		always = yes
				#	}
				#	#Only get rid of family members if we dislike them
				#	trigger_else = {
				#		scope:actor = {
				#			opinion = {
				#				target = scope:recipient
				#				value <= medium_negative_opinion
				#			}
				#		}
				#	}
				#}
				#We're not Byzantium but plain AI
				#AGOT Modified
				#trigger_else = {
				scope:recipient = {
					is_ai = yes #Not gonna depose player characters, for now
					is_close_or_extended_family_of = scope:actor
					NOT = {
						is_heir_of = scope:actor
					}
				}
				scope:actor = {
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
				custom_description = {
					text = "release_vows_invalid_not_your_court"
					object = scope:recipient
					subject = scope:actor
					OR = {
						scope:recipient = { is_courtier_of = scope:actor }
						scope:recruit = yes
					}
				}
			}
			#Enhanced Take the Vows for Byzantium players -- who do we want to boot to a monastery far, far away?
			#AGOT Disabled
			#trigger_else_if = {
			#	limit = {
			#		scope:actor = {
			#			culture = { has_cultural_pillar = heritage_byzantine }
			#		}
			#	}
			#	scope:recipient = {
			#		is_ai = yes #Not gonna depose player characters, for now
			#		custom_description = {
			#			text = "release_byz_vows_invalid"
			#			object = scope:recipient
			#			subject = scope:actor
			#			OR = {
			#				is_close_or_extended_family_of = scope:actor
			#				is_vassal_or_below_of = scope:actor
			#				has_relation_rival = scope:actor
			#				is_courtier_of = scope:actor
			#			}
			#		}
			#	}
			#}
			#Otherwise standard procedure Take the Vows requirements
			trigger_else = {
				scope:recipient = {
					is_ai = yes #Not gonna depose player characters, for now
				}
				scope:actor = { is_close_or_extended_family_of = scope:recipient } #Triggering I_AM_NOT instead of CHARACTER_IS_NOT makes the tooltip look less cursed
				custom_description = {
					text = "release_vows_invalid_not_your_court"
					object = scope:recipient
					subject = scope:actor
					OR = {
						scope:recipient = { is_courtier_of = scope:actor }
						scope:recruit = yes
					}
				}

			}
			custom_description = {
				text = "release_vows_invalid_not_your_faith"
				object = scope:recipient
				subject = scope:actor
				trigger_if = {
					limit = {
						NOT = { scope:recipient.faith = scope:actor.faith }
					}
					scope:demand_conversion = yes
				}
			}
			custom_description = {
				text = "release_executioner_invalid_take_vows_condition"
				object = scope:recipient
				scope:become_executioner = no
			}
			custom_description = {
				text = "release_court_whore_invalid_take_vows_condition"
				object = scope:recipient
				scope:become_court_whore = no
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:banish = no
			}
			scope:recipient = {
				age >= 10
				NOR = {
					has_trait = excommunicated
					has_trait = devoted
					has_trait = incapable
				}
				#Do they have the "wrong" marriage type?
				NOR = {
					custom_description = {
						text = is_married_matrilineally
						subject = scope:recipient
						any_spouse = {
							is_female = yes
							matrilinear_marriage = yes
						}
					}
					custom_description = {
						text = is_married_patrilineally
						subject = scope:recipient
						any_spouse = {
							is_male = yes
							patrilinear_marriage = yes
						}
					}
					custom_description = {
						text = matrilinear_betrothal
						subject = scope:recipient
						exists = betrothed
						betrothed = {
							is_female = yes
							matrilinear_betrothal = yes
						}
					}
					custom_description = {
						text = patrilinear_betrothal
						subject = scope:recipient
						exists = betrothed
						betrothed = {
							is_male = yes
							patrilinear_betrothal = yes
						}
					}
				}
			}
		}
	}
	send_option = {
		flag = become_executioner
		localization = "RELEASE_AS_EXECUTIONER"
		is_shown = {
			has_ep1_court_positions_dlc_trigger = yes
			scope:actor = {
				has_royal_court = yes
			}
			scope:recipient = {
				is_adult = yes
			}
			#AGOT Added
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			scope:actor = {
				can_employ_court_position_type = executioner_court_position #Unop: Check that the actor can employ an executioner
				NOT = { employs_court_position = executioner_court_position }
			}
			scope:recipient = {
				trigger_if = {
					limit = { scope:recruit = yes }
					custom_description = {
						text = "release_executioner_invalid_recruit"
						object = scope:recipient
						scope:recruit = yes
					}
				}
				trigger_else = {
					is_courtier_of = scope:actor
				}

				custom_description = {
					text = "release_executioner_invalid_take_vows_condition"
					object = scope:recipient
					scope:take_vows = no
				}
				NOT = { is_spouse_of = scope:actor  }
			}
		}
	}

	send_option = {
		flag = become_court_whore
		localization = "RELEASE_AS_COURT_WHORE"
		is_shown = {
			has_ep1_court_positions_dlc_trigger = yes
			NOT = {has_game_rule = court_whore_prison_disabled}
			scope:recipient = {
				court_whore_eligible_whore_trigger = yes
			}
		}
		is_valid = {
			scope:actor = {
				can_employ_court_position_type = court_whore_court_position #Unop: Check that the actor can employ an executioner
				any_court_position_holder = {
					type = court_whore_court_position
					count < 10
				}
			}
			scope:recipient = {
				trigger_if = {
					limit = { scope:recruit = yes }
					custom_description = {
						text = "release_court_whore_invalid_recruit"
						object = scope:recipient
						scope:recruit = yes
					}
				}
				trigger_else = {
					OR = {
						is_courtier_of = scope:actor
						is_vassal_of = scope:actor
					}
				}

				custom_description = {
					text = "release_court_whore_invalid_take_vows_condition"
					object = scope:recipient
					scope:take_vows = no
				}
				# NOT = { is_spouse_of = scope:actor  }
			}
		}
	}

	send_option = {
		flag = recruit
		localization = "RELEASE_RECRUIT"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						has_relation_best_friend = scope:actor
						has_relation_friend = scope:actor
						has_relation_lover = scope:actor
						has_relation_soulmate = scope:actor
						has_secret_relation_lover = scope:actor
						is_heir_of = scope:actor
					}
				}
			}
			scope:recipient = {
				is_ruler = no
				NOT = { is_courtier_of = scope:actor }
				OR = {
					is_adult = yes
					AND = {
						is_adult = no
						OR = {
							trigger_if = {
								limit = { exists = liege }
								NOT = { is_heir_of = liege }
							}
							NOT = { exists = liege }
						}
					}
				}
			}
			# CSR: Disable Recruit for slaves since they will be returned automatically
			scope:recipient = {
				carnx_is_slave_trigger = no
			}
			#AGOT Added, NW can only forcibly recruit men over a certain age and wildling children
			trigger_if = {
				limit = {
					scope:actor = { has_trait = nightswatch }
				}
				NOR = {
					scope:recipient = { is_female = yes }
					scope:recipient = { age < 7 }
					AND = {
						scope:recipient.culture = { agot_is_wildling_culture = yes }
						scope:recipient = { age > 13 }
					}
				}
			}
			#AGOT Added, can't forcibly recruit a watchman
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
	}

	send_option = {
		flag = disfigure
		localization = "RELEASE_DISFIGURE"
		is_shown = {
			scope:actor = {
				government_allows = administrative
				culture = { has_cultural_tradition = tradition_ep3_palace_politics }
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
			scope:recipient = {
				is_adult = yes
			}
		}
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = disfigured }
			}
			# Byzantines can't disfigure those not in their realm
			#AGOT Disabled
			#trigger_if = {
			#	limit = {
			#		scope:actor = {
			#			culture = { has_cultural_pillar = heritage_byzantine }
			#		}
			#	}
			#	scope:recipient = {
			#		custom_description = {
			#			text = "release_byz_disfigure_invalid"
			#			object = scope:recipient
			#			subject = scope:actor
			#			OR = {
			#				is_close_or_extended_family_of = scope:actor
			#				is_vassal_or_below_of = scope:actor
			#				has_relation_rival = scope:actor
			#				is_courtier_of = scope:actor
			#			}
			#		}
			#	}
			#}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:blind = no
				scope:castrate = no
			}
		}
	}

	send_option = {
		flag = blind
		localization = "RELEASE_BLIND"
		is_shown = {
			scope:actor = {
				is_adult = yes
				culture = { has_cultural_parameter = can_blind_prisoners }
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
			scope:recipient = {
				is_adult = yes
			}
		}
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = blind }
			}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:disfigure = no
				scope:castrate = no
			}
		}
	}

	send_option = {
		flag = castrate
		localization = "RELEASE_CASTRATE"
		is_shown = {
			scope:recipient = {
				is_imprisoned_by = scope:actor
				is_eunuch_trigger = no
				is_male = yes
			}
			scope:actor = {
				is_adult = yes
				culture = {
					has_cultural_parameter = can_castrate_prisoners
				}
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
		}
		is_valid = {
			scope:recipient = {
				is_eunuch_trigger = no
			}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:disfigure = no
				scope:blind = no
			}
		}
	}

	#AGOT Added
	send_option = {
		flag = mega_war_switch_sides
		localization = "MEGA_WAR_SWITCH_SIDES"
		is_shown = {
			custom_tooltip = {
				text = "MEGA_WAR_SWITCH_SIDES"
				agot_mw_switch_side_send_trigger = yes
			}
		}
	}

	#AGOT Added - AGOT Strip Knighthood
	send_option = {
		flag = agot_strip_knighthood
		localization = "agot_strip_knighthood"
		is_shown = {
			custom_tooltip = {
				text = "agot_strip_knighthood"
				agot_can_revoke_knighthood_punishment_trigger = yes
			}
		}
	}

	#AGOT Added - Banish to Essos
	send_option = {
		flag = agot_banish_to_essos
		localization = "agot_banish_to_essos"
		is_shown = {		# Mostly same as banish
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						AND = {
							is_landed = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 100
							scope:actor.ai_greed >= high_positive_ai_value
						}
						AND = {
							scope:actor = {
								has_banish_reason = scope:recipient
							}
							scope:actor = {
								opinion = {
									target = scope:recipient
									value <= medium_negative_opinion
								}
							}
						}
					}
				}
			}
			scope:recipient = {
				OR = {
					target_is_liege_or_above = scope:actor
					is_pool_character = yes
				}
				NOT = { has_trait = high_septon }
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:take_vows = no
			}
			scope:recruit = no # Should be impossible to have both but just in case
			scope:banish = no
			NOT = {
				scope:recipient = {
					is_spouse_of = scope:actor
				}
			}
			# CSR: Disable Banish to Essos for slaves since they will be returned automatically
			scope:recipient = {
				carnx_is_slave_trigger = no
			}

			scope:actor = {
				NOR = {
					capital_province = {
						geographical_region = world_essos
					}
					has_trait = nightswatch
					culture = { agot_is_wildling_culture = yes }
				}
			}

			scope:recipient = {
				NOT = { has_trait = nightswatch }
				NOT = { has_trait = kingsguard }
			}
		}
	}

	send_options_exclusive = no

	auto_accept = {
		scope:demand_conversion = no
		scope:renounce_claims = no
		scope:banish = no
		scope:gain_hook = no
		scope:take_vows = no
		scope:recruit = no
		#AGOT Added
		scope:mega_war_switch_sides = no
		scope:agot_strip_knighthood = no
		scope:agot_banish_to_essos = no
	}

	ai_accept = {
		base = 0
		modifier = {
			#AGOT Added, only for non-banishment
			trigger = {
				AND = {
					scope:banish = no
					scope:agot_banish_to_essos = no
				}
			}
			add = 100
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal <= 20 }
				scope:demand_conversion = yes
			}
			#AGOT Modified, less likely to convert
			#add = -20
			add = -50
			desc = "CONVERSION_NEGATIVE_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal > 20 }
				scope:demand_conversion = yes
			}
			add = {
				value = ai_zeal
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value = faith_astray_level
							}
						}
					}
					#AGOT Modified, less likely to convert
					#multiply = -1
					multiply = -2
				}
				else = {
					#AGOT Modified, less likely to convert
					#multiply = -2
					multiply = -5
				}
			}
			desc = "CONVERSION_NEGATIVE_REASON"
		}
		modifier = {
			add = -25
			trigger = {
				scope:renounce_claims = yes
				ai_greed < 0
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 0
				ai_greed < 26
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_executioner = yes
				# Sadists don't care about becoming an executioner
				NOR = {
					has_trait = sadistic
					has_trait = callous
				}
			}
			desc = "BECOME_EXECUTIONER_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_court_whore = yes
				#court_whore_willing_trigger = no
			}
			desc = "BECOME_COURT_WHORE_REASON"
		}
		modifier = {
			add = 50
			trigger = {
				scope:become_court_whore = yes
				court_whore_is_prostitute_trigger = yes
			}
			desc = "BECOME_COURT_WHORE_ALREADY_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_court_whore = yes
				OR = {
					has_trait = arrogant
					has_trait = stubborn
					has_trait = brave
					has_trait = chaste
				}
				court_whore_is_prostitute_trigger = no
			}
			desc = "BECOME_COURT_WHORE_PRIDEFUL_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_court_whore = yes
				is_lowborn = no
				court_whore_is_prostitute_trigger = no
			}
			desc = "BECOME_COURT_WHORE_NOBLE_REASON"
		}
		modifier = {
			add = 50
			trigger = {
				scope:become_court_whore = yes
				court_whore_willing_trigger = yes
			}
			desc = "BECOME_COURT_WHORE_WILLING_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_court_whore = yes
				OR = {
					# is_married = yes
					# is_concubine = yes
					any_consort = {
						scope:recipient = {
							opinion = {
								target = prev
								value >= low_negative_opinion
							}
						}
					}
					any_relation = {
						type = lover
						count > 0
					}
					any_relation = {
						type = soulmate
						count > 0
					}
				}
			}
			desc = "BECOME_COURT_WHORE_MARRIED_REASON"
		}
		modifier = {
			add = 20
			trigger = {
				scope:become_court_whore = yes
				any_consort = {
					scope:recipient = {
						opinion = {
							target = prev
							value < low_negative_opinion
						}
					}
				}
			}
			desc = "BECOME_COURT_WHORE_HATE_MARRIED_REASON"
		}
		modifier = {
			add = -75
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 26
				ai_greed < 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -95
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:banish = yes
			}
			NOT = {
				scope:actor = {
					has_imprisonment_reason = scope:recipient
					culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
				}
			}
			desc = "BANISH_NEGATIVE_REASON"
		}
		modifier = { # Legalistic tradition
			add = legalistic_vassal_punishment_acceptance
			trigger = {
				scope:banish = yes
			}
			scope:actor = {
				has_imprisonment_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
			desc = tradition_legalistic_name
		}
		modifier = {
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient = {
							ai_vengefulness > 0
						}
					}
					subtract = ai_vengefulness
				}
			}
			trigger = {
				scope:gain_hook = yes
			}
			desc = "GAIN_HOOK_NEGATIVE_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
			}
			desc = "TAKE_VOWS_NEGATIVE_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = lustful
			}
			desc = "TAKE_VOWS_LUSTFUL_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = rakish
			}
			desc = "TAKE_VOWS_RAKISH_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = fornicator
			}
			desc = "TAKE_VOWS_FORNICATOR_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = seducer
			}
			desc = "TAKE_VOWS_SEDUCER_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = deviant
			}
			desc = "TAKE_VOWS_DEVIANT_REASON"
		}
		modifier = {
			add = {
				value = -15
				multiply = num_sinful_traits
			}
			trigger = {
				scope:take_vows = yes
				num_sinful_traits > 1
			}
			desc = "TAKE_VOWS_SINS_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = cynical
			}
			desc = "TAKE_VOWS_CYNICAL_REASON"
		}
		modifier = {
			add = -10
			trigger = {
				scope:recruit = yes
				NOT = {
					scope:actor = {
						culture = {
							has_cultural_parameter = can_recruit_prisoners_easily
						}
					}
				}
			}
			desc = "RECRUITMET_NEGATIVE_REASON"
		}
		# Struggle
		modifier = {
			trigger = {
				scope:demand_conversion = no
				scope:renounce_claims = no
				scope:banish = no
				scope:gain_hook = no
				scope:take_vows = no
				scope:recruit = no
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
						}
					}
					add = 200
				}
			}
		}

		#AGOT Added, Megawars
		agot_mw_switch_sides_modifier = yes

		#AGOT Added, Strip knighthood
		modifier = {
			trigger = {
				OR = {
					scope:recipient = { ai_zeal <= 50 }
					scope:recipient = {
						NOT = {
							faith = {
								has_doctrine_parameter = can_grant_knighthood
							}
						}
					}
				}
				scope:agot_strip_knighthood = yes
			}
			add = -50
			desc = "NOT_RELIGIOUS_ATTACHED_TO_KNIGHTHOOD_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal > 50 }
				scope:recipient = {
					faith = {
						has_doctrine_parameter = can_grant_knighthood
					}
				}
				scope:agot_strip_knighthood = yes
			}
			add = {
				value = ai_zeal
				multiply = -1
			}
			desc = "RELIGIOUS_ATTACHED_TO_KNIGHTHOOD_REASON"
		}

		#AGOT Added, Banishment
		modifier = { # Base modifier for banishment
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
			}
			add = 75
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = { # Cannot banish your liege or higher!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					is_liege_or_above_of = scope:actor
				}
			}
			add = -200
			desc = "AGOT_CANNOT_BANISH_LIEGE"
		}
		modifier = { # Cannot banish the family of your liege or higher!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					any_close_family_member = {
						NOT = { this = scope:actor }
						is_liege_or_above_of = scope:actor
					 }
				}
			}
			add = -100
			desc = "AGOT_CANNOT_BANISH_LIEGE_FAMILY"
		}
		modifier = { # Cannot banish your peers or betters!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					is_landed = yes
					scope:actor.primary_title.tier <= scope:recipient.primary_title.tier
				}
			}
			add = -200
			desc = "AGOT_CANNOT_BANISH_PEER"
		}
		modifier = { # Cannot banish the family of your peers or betters!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					any_close_family_member = {
						NOT = { this = scope:actor }
						is_landed = yes
						scope:actor.primary_title.tier <= this.primary_title.tier
					}
				}
			}
			add = -100
			desc = "AGOT_CANNOT_BANISH_PEER_FAMILY"
		}
		modifier = { # Cannot banish outsiders
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					culture = { agot_is_wildling_culture = no }
					NAND = {
						is_landed = yes
						scope:actor.primary_title.tier <= scope:recipient.primary_title.tier
					}
					OR = {
						any_close_family_member = {
							NOT = { this = scope:actor }
							is_landed = yes
							NOR = {
								is_vassal_or_below_of = scope:actor
								is_liege_or_above_of = scope:actor
							}
						}
						NOR = {
							is_vassal_or_below_of = scope:actor
							is_liege_or_above_of = scope:actor
						}
					}
					NAND = {
						is_landed = no
						NOT = {
							any_close_family_member = {
								is_landed = yes
							}
						}
					}
				}
			}
			add = -150
			desc = "AGOT_CANNOT_BANISH_OUTSIDER"
		}
	}

	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 1

	ai_potential = {
		has_prisoners = yes
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 20
			scope:demand_conversion = yes
		}
		modifier = {
			add = 100
			scope:demand_conversion = yes
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}
		modifier = {
			add = 30
			scope:renounce_claims = yes
		}
		modifier = {
			add = 50
			scope:banish = yes
		}
		modifier = {
			add = 30
			scope:take_vows = yes
		}
		modifier = {
			add = 10
			scope:recruit = yes
		}
		modifier = {
			add = 20
			scope:become_court_whore = yes
		}
		modifier = {
			add = -20
			scope:actor = {
				has_trait = just
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = -50
			scope:actor = {
				has_trait = chaste
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = -50
			scope:actor = {
				has_trait = compassionate
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = lustful
				is_attracted_to_gender_of = scope:recipient
				scope:recipient.attraction >= medium_positive_attraction
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 50
			scope:actor = {
				is_deviant_trigger = yes
				is_attracted_to_gender_of = scope:recipient
				scope:recipient.attraction >= medium_positive_attraction
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = deviant
				is_attracted_to_gender_of = scope:recipient
				scope:recipient.attraction >= medium_positive_attraction
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = seducer
				is_attracted_to_gender_of = scope:recipient
				scope:recipient.attraction >= medium_positive_attraction
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 50
			scope:actor = {
				has_trait = rakish
				is_attracted_to_gender_of = scope:recipient
				scope:recipient.attraction >= medium_positive_attraction
			}
			scope:become_court_whore = yes
		}
		modifier = {
			add = 30
			scope:disfigure = yes
		}
		modifier = {
			add = 20
			scope:blind = yes
		}
		modifier = {
			add = 50
			scope:castrate = yes
		}
		#AGOT Added
		modifier = {
			add = 30
			scope:agot_banish_to_essos = yes
		}
		modifier = { # Rivals can rot
			add = -40
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Rivals can whore
			add = 40
			scope:become_court_whore
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Rivals can rot FOREVER if vengeful
			add = -100
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:actor.ai_vengefulness >= very_high_positive_ai_value
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Rivals WILL WHORE FOREVER if vengeful
			add = 100
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:actor.ai_vengefulness >= very_high_positive_ai_value
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Compassionate characters don't want to keep children in their dungeon for too long
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_positive_ai_value
			}
			scope:recipient = {
				is_adult = no
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Very compassionate characters tend to release prisoners
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_positive_ai_value
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Somewhat compassionate characters tend to keep people in their dungeon for a while
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= medium_positive_ai_value
			}
			scope:recipient = {
				is_playable_character = no
				time_in_prison = { years > 3 }
			}
		}
		modifier = { # Only truly discompassionate characters will have their dungeon full of hapless victims after 5 years
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_negative_ai_value
			}
			scope:recipient = {
				is_playable_character = no
				time_in_prison = { years > 5 }
			}
		}
		modifier = { # Most AI characters will let family out...
			add = 10
			scope:actor = {
				is_at_war = no
				OR = {
					ai_compassion >= very_high_positive_ai_value
					AND = {
						ai_compassion >= high_negative_ai_value
						opinion = {
							target = scope:recipient
							value >= low_negative_opinion
						}
					}
				}
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
				is_playable_character = no
				is_close_family_of = scope:actor
			}
		}
		modifier = { # Almost all will let their own children out
			add = 40
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_negative_ai_value
			}
			scope:recipient = {
				is_playable_character = no
				is_child_of = scope:actor
			}
		}
		# Struggle
		modifier = {
			trigger = {
				scope:demand_conversion = no
				scope:renounce_claims = no
				scope:banish = no
				scope:gain_hook = no
				scope:take_vows = no
				scope:recruit = no
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							NOT = {
								ai_greed >= 25
							}
							OR = {
								ai_compassion > 50
								AND  = {
									ai_compassion > 0
									scope:recipient = {
										time_in_prison = { years > 1 }
									}
								}
							}
						}
					}
					add = 200
				}
			}
		}
		modifier = { # Family Feud
			add = -50
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
		}
		modifier = { # Family Feud can whore lol
			add = 50
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:become_court_whore = yes
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
		}
		#Byz AI can shove vassals off to remote monasteries - weigh that here
		#AGOT Disabled
		#modifier = {
		#	add = -10
		#	scope:take_vows = yes
		#	scope:actor = {
		#		culture = { has_cultural_pillar = heritage_byzantine }
		#	}
		#	scope:recipient = { is_vassal_or_below_of = scope:actor }
		#}

		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		#don't release prisoners that are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:recipient = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
		#AGOT Added
		modifier = {
			factor = 0
			scope:recipient = {
				has_character_modifier = locked_in_maidenvault
			}
		}
	}
}